//
//  KBAlbumsTableViewCell.m
//  喜马拉雅改良版框架
//
//  Created by dllo on 15/12/26.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//
// 封装的header区域
#import "KBAlbumsTableViewCell.h"

@implementation KBAlbumsTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self)
    {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews
{
    // 标题
    _title = [[UILabel alloc] init];
    _title.font = [UIFont systemFontOfSize:15];
    _title.textColor = [UIColor colorWithRed:0.13 green:0.15 blue:0.15 alpha:1];
    [self.contentView addSubview:_title];
    [_title mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(7);
        make.left.mas_equalTo(10);
        make.width.mas_equalTo(350);
        make.height.mas_equalTo(25);
        
    }];
    // 播放次数
    UIImageView *playtime = [[UIImageView alloc] init];
    playtime.image = [UIImage imageNamed:@"sound_playtimes@2x.png"];
    [self.contentView addSubview:playtime];
    [playtime mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(_title.mas_bottom).offset(10);
        make.left.mas_equalTo(_title.mas_left).offset(10);
        make.width.mas_equalTo(8);
        make.height.mas_equalTo(10);
    }];
    
    _playtimes = [[UILabel alloc] init];
    _playtimes.font = [UIFont systemFontOfSize:12];
    _playtimes.textColor = [UIColor colorWithRed:0.67 green:0.68 blue:0.72 alpha:1];
    [self.contentView addSubview:_playtimes];
    
    [_playtimes mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(playtime.mas_top).offset(-2);
        make.left.mas_equalTo(playtime.mas_right).offset(5);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(12);
    }];
    // 时长
    UIImageView *duration = [[UIImageView alloc] init];
    duration.image = [UIImage imageNamed:@"iconfont-biao.png"];
    [self.contentView addSubview:duration];
    [duration mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(playtime.mas_top);
        make.left.mas_equalTo(_playtimes.mas_right).offset(10);
        make.width.mas_equalTo(11);
        make.height.mas_equalTo(11);
        
    }];
    
    _duration = [[UILabel alloc] init];
    _duration.textColor = [UIColor colorWithRed:0.67 green:0.68 blue:0.72 alpha:1];
    _duration.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:_duration];
    [_duration mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(_playtimes.mas_top);
        make.left.mas_equalTo(duration.mas_right).offset(5);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(12);
        
    }];
    // 时间戳
    _createdAt = [[UILabel alloc] init];
    _createdAt.font = [UIFont systemFontOfSize:12];
    _createdAt.textColor = [UIColor colorWithRed:0.67 green:0.68 blue:0.72 alpha:1];
    [self.contentView addSubview:_createdAt];
    [_createdAt mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(duration.mas_top);
        make.right.mas_equalTo(-5);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(10);
        
    }];
    
    

}
- (void)setModel:(KBalbumsTableModel *)model
{
    // 标题
    _title.text = model.title;
    // 播放次数
    if ((CGFloat)model.playtimes > 9999)
    {
        _playtimes.text = [NSString stringWithFormat:@"%.2f万", (CGFloat)model.playtimes/10000];
    }
    else
    {
        _playtimes.text = [NSString stringWithFormat:@"%ld", model.playtimes];
    }
    
    // 播放时长
    _duration.text = [NSString stringWithFormat:@"%ld:%ld", (NSInteger)model.duration/60, (NSInteger)model.duration%60];
    
    // 时间戳
    NSInteger number = model.createdAt.integerValue;
    NSString *string = [LXTimeTool getDateWithUpdatedAt:number];
    _createdAt.text = string;
//    NSLog(@"===%ld", number);
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
